import { config } from './config';

let mark = '';
let nowName = '';
let s = null;
// 创建样式
export function setCityDarkMap(res, data) {
  if (!res) nowName = '';
  if (res) {
    console.log(nowName, res.name);
    if (nowName == res.name) return;
    nowName = res.name;
  }
  mark && config.map.remove(mark);
  const { AMap } = config;
  mark = new AMap.Marker({
    clickable: false,
    cursor: 'auto',
    anchor: 'bottom-center',
    position: res.centroid,
    offset: new AMap.Pixel(328, 156),
    zIndex: 300,
    content: `
      <div class="map-modal-cnt" id="map-modal-cnt">

      </div>
    `
  });
  config.map.add(mark);
  s && clearTimeout(s);
  window.PolygonCreateModal && window.PolygonCreateModal(res, data, (dom) => {
    s = setTimeout(() => {
      clearTimeout(s);
      document.getElementById('map-modal-cnt').appendChild(dom);
    }, 300);
  });
  return mark;
}

export function clearCityDarkMap() {
  console.log('clearCityDarkMap');
  nowName = '';
  document.getElementById('map-modal-cnt').innerHTML = '';
  mark && config.map.remove(mark);
  window.PolygonClearModal && window.PolygonClearModal();
}
